#include "service_main.h"
#include "../common/command_line_builder.h"
#include "../common/const_pcagent.h"
#include "../common/pcagent_utils.h"

// A private object map with custom registration works best, even though this
// stuff is deprecated. This is because LongkeyPCAgent.exe has other objects
// defined elsewhere and we do not want to expose those from the service.
BEGIN_OBJECT_MAP(object_map_longkey_pcagent)
	//OBJECT_ENTRY(__uuidof(LongkeyPCAgent3ServiceClass), Update3COMClassService)
END_OBJECT_MAP()

CommandLineMode PCAgentServiceMode::commandline_mode()
{
	return COMMANDLINE_MODE_SERVICE;
}

CString PCAgentServiceMode::reg_name()
{
	return kRegValueServiceName;
}

CString PCAgentServiceMode::default_name()
{
	return kServicePrefix;
}

DWORD PCAgentServiceMode::service_start_type()
{
	return SERVICE_AUTO_START;
}

_ATL_OBJMAP_ENTRY* PCAgentServiceMode::object_map()
{
	return object_map_longkey_pcagent;
}

bool PCAgentServiceMode::allow_access_from_medium()
{
	return false;
}

CString PCAgentServiceMode::app_id_string()
{
	return "";//GuidToString(__uuidof(PCAgentServiceClass));
}

CString PCAgentServiceMode::GetCurrentServiceName()
{
	return pcagent_utils::GetCurrentVersionedName(true, 
		reg_name(), default_name());
}

HRESULT PCAgentServiceMode::PreMessageLoop()
{
	SERVICE_LOG(L1, (_T("[Starting PC Agent core ...]")));
	CommandLineBuilder builder(COMMANDLINE_MODE_CORE);
	CString args = builder.GetCommandLineArgs();
	return pcagent_utils::StartPCAgentWithArgs(true, args, NULL);
}